<template>
  <div class="app-container">
    <el-row>
      <el-col>
        <el-card class="box-card card-primary" style="max-width: 600px; margin: auto">
          <div slot="header" class="clearfix">
            <span>登陆信息</span>
          </div>
          <br>
          <el-form label-position="left" label-width="130px">
            <el-form-item label="用户名：" width="120">
              <span>{{userName}}</span>
            </el-form-item>
            <el-form-item label="岗位：" width="120">
              <span>{{postName}}</span>
            </el-form-item>
            <el-form-item label="当前IP地址：" width="120">
              <span>{{userIp}}</span>
            </el-form-item>
            <el-form-item label="浏览器版本：" width="120">
              <span>{{browserName}}&emsp;{{browserVersion}}
              </span>
              <el-tooltip v-if="!browserSupport[browserName] || browserSupport[browserName]>browserMajor" class="item" effect="light" content="请升级你的浏览器，或者使用最新版Chrome。支持最新IE11/Chrome/Firefox/QQ浏览器/百度浏览器/360浏览器。" placement="top">
                <el-button type="text">（可能不兼容）</el-button>
              </el-tooltip>
            </el-form-item>
          </el-form>
					<div style="text-align: right;">
<!--						<el-button v-if="aotuPower" round @click="winOpen('55585')">机器写稿生成管理</el-button>-->
<!--						<el-button v-if="flowchartPower" round @click="winOpen('3091')">产业链管理</el-button>-->
<!--            <el-button v-if="stockMap" round @click="winOpen('55556')">股市地图</el-button>-->
					</div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
  import { baseUrl, doRequestGet } from '../../utils/request'
  import { getPostName } from '../../utils/auth'

  export default {
    name: 'homepage',
    data() {
      return {
        browserSupport: {
          'Chrome': 63,
          'Firefox': 61,
          'IE': 11,
          'Edge': 17,
          'QQBrowser': 10,
          'BIDUBrowser': 8
        },
        browserName: '',
        browserVersion: '',
        browserMajor: '',
        engineName: '',
        engineVersion: '',
        osName: '',
        osVersion: '',
        deviceModel: '',
        deviceType: '',
        deviceVendor: '',
        userName: '',
        postName: '',
        userIp: '',
        aotuPower: true,
        flowchartPower: true,
        stockMap:true
      }
    },
    created() {
      const parser = new UAParser().getResult()
      // console.log(parser)
      const userName = this.$store.state.user.name
      const postName = getPostName()
      // console.log(postName)
      doRequestGet(baseUrl + 'system/user/ip', {}).then(response => {
        this.userIp = response.Data[0]
      })
      this.browserName = parser.browser.name
      this.browserVersion = parser.browser.version
      this.browserMajor = parser.browser.major
      this.engineName = parser.engine.name
      this.engineVersion = parser.engine.version
      this.osName = parser.os.name
      this.osVersion = parser.os.version
      this.deviceModel = parser.device.model
      this.deviceType = parser.device.type
      this.deviceVendor = parser.device.vendor
      this.postName = postName
      this.userName = userName
    },
    mounted() {
    	let arr = this.$store.state.user.navmenu;
    	let isAuto = arr.filter(item => item.Code == "aiwrite");
    	let isflow = arr.filter(item => item.Code == "flowchart");
    	if(!isAuto.length) this.aotuPower = false;
    	if(!isflow.length) this.flowchartPower = false;
    },
		methods: {
			winOpen(num){
        var nowUrl = location.href;
				if(num == 55585){
          if(nowUrl.indexOf("10.8.99.116") > -1){
            // 生产环境
            window.open("http://10.8.99.116:55585/#/readme");
          }else if(nowUrl.indexOf("10.8.8.147") > -1){
            window.open("http://10.8.8.147:55585/#/readme");
          }
          else {
            // 测试环境
            window.open("http://10.8.99.119:55585/#/readme");
          }
				}else if(num  == 3091){
          if(nowUrl.indexOf("10.8.99.116") > -1){
            // 生产环境
            window.open("http://10.8.99.116:3091/flowchart");
          }else if(nowUrl.indexOf("10.8.8.147") > -1){
            window.open("http://10.8.8.147:3091/flowchart");
          }
          else {
            // 测试环境
            window.open("http://10.8.99.119:3091/flowchart");
          }
				} else if(num  == 55556){
          if(nowUrl.indexOf("10.8.99.116") > -1){
            // 生产环境
            window.open("http://10.8.99.116:55556/stockMap.html?theme=default&dt_from=web&consoleMode=0&dt_page_type=11&webviewType=userActivitesType");
          }else if(nowUrl.indexOf("10.8.8.147") > -1){
            window.open("http://10.8.8.147:55556/stockMap.html?theme=default&dt_from=web&consoleMode=0&dt_page_type=11&webviewType=userActivitesType");
          }else {
            window.open("http://10.8.99.116:55556/stockMap.html?theme=default&dt_from=web&consoleMode=0&dt_page_type=11&webviewType=userActivitesType");
          }
          // window.open("http://10.8.99.116:55586/#/readme");
				}
			}
		}
  }
</script>
